import { defHttp } from '@/utils/http/axios'

import type { DictAddReq, DictDeleteReq, DictQuery, DictUpdateReq } from '@/model/sys/dictModel'

enum Path {
  List = '/dict/list',
  ValuesMap = '/dict/values-map',
  Add = '/dict/add',
  Update = '/dict/update',
  Delete = '/dict/delete',
}

export const dictApi = {
  list(params?: DictQuery) {
    return defHttp.post({ url: Path.List, params })
  },
  valuesMap() {
    return defHttp.post({ url: Path.ValuesMap })
  },
  add(params: DictAddReq) {
    const { cssClass, color } = params
    const req = { ...params, dictMeta: JSON.stringify({ cssClass, color }) }
    return defHttp.post({ url: Path.Add, params: req })
  },
  update(params: DictUpdateReq) {
    const { cssClass, color } = params
    const req = { ...params, dictMeta: JSON.stringify({ cssClass, color }) }
    return defHttp.post({ url: Path.Update, params: req })
  },
  delete(params: DictDeleteReq) {
    return defHttp.post({ url: Path.Delete, params })
  },
}
